﻿using OABackground.Entities;
using OABackground.Infrastructure;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading.Tasks;

namespace OABackground.Services
{
    public class StudentService
    {
        private StudentRepository studentRepo = new StudentRepository();
        private object O = new object();
        public List<string> Xing = new List<string>() {
        "朱", "秦", "尤", "许", "何", "吕", "施", "张", "孔", "曹", "严", "华", "金", "魏", "陶", "姜",
        "游", "竺", "权", "逑", "盖", "益", "桓", "公", "仉", "督", "晋", "楚", "阎", "法", "汝", "鄢",
        };
        string _lastNameMan = "刚伟勇毅俊峰强军平保东文辉中茂进林有坚和彪博诚先敬震振壮会思群行时泰盛雄琛钧冠策腾楠榕风航弘";
        string _lastNameWoMan = "秀娟英华慧巧琦晶妍茜秋珊莎锦黛青倩婷姣婉娴瑾颖露瑶怡婵雁蓓纨仪荷丹蓉眉君琴蕊薇菁梦岚苑芸菲寒伊亚宜可姬舒影荔枝思丽墨";
        public List<string> GetManName()
        {
            Stopwatch sw = new Stopwatch();
            sw.Start();
            List<string> NameArray = new List<string>();
            int XingLen = Xing.Count;
            char[] ManChar = _lastNameMan.ToCharArray();
            char[] WoManChar = _lastNameWoMan.ToCharArray();
            int ManNameLen = ManChar.Length;
            int WoManNameLen = WoManChar.Length;
                                                
            foreach (var item in Xing)
            {
                foreach (var Ming in ManChar)
                {
                    NameArray.Add(item + Ming);
                }
            }
            foreach (var item in Xing)
            {
                foreach (var Ming in WoManChar)
                {
                    NameArray.Add(item + Ming);
                }
            }
            sw.Stop();
            TimeSpan ts2 = sw.Elapsed;
            return NameArray;
        }
        //public StudentService()
        //{
        //    List<string> NameArray = GetManName();
        //    int i = 0;
        //    int beginNum = 1606040503;
        //    long beginPhone = 13521523151;
        //    long beginParPhone = 18821523151;
        //    foreach (var item in NameArray)
        //    {
        //        Student student = new Student();
        //        student.Name = item;
        //        if (i++ % 2 == 0)
        //        {
        //            student.Sex = "男";
        //        }
        //        else
        //        {
        //            student.Sex = "女";
        //        }
        //        student.Class = item + (i % 2).ToString() + "班";
        //        student.Grade = "2016级";
        //        student.Id = "S0" + (++beginNum).ToString();
        //        student.Dormitory = "南山" + (i % 2).ToString() + "#" + (i % 2).ToString() + (i % 3).ToString() + (i % 4).ToString();
        //        student.SelfPhone = (beginPhone++).ToString();
        //        student.Parent = item.Substring(0, 1);
        //        student.ParentPhone = (beginParPhone++).ToString();
        //        studentRepo.Add(student);
        //    }
        //}
        public enum DepartmentId
        {
            js = 0,
            zjc,
            cwc,
            xz
        }
        public StudentService()
        {
            List<string> NameArray = GetManName();
            int i = 0;
            long beginNum = 16060701015;
            long beginPhone = 13809153151;
            foreach (var item in NameArray)
            {
                Teacherinfomation teacherinfomation = new Teacherinfomation();
                Teacherpassword teacherPassword = new Teacherpassword();
                teacherinfomation.Tname = item;
                if (i++ % 2 == 0)
                {
                    teacherinfomation.Sex = "男";
                }
                else
                {
                    teacherinfomation.Sex = "女";
                }
                teacherinfomation.Profession = "讲师";
                teacherinfomation.Teacherid = "T" + (++beginNum).ToString();
                teacherinfomation.EntryTime = DateTime.Now;
                teacherPassword.Teacherid = teacherinfomation.Teacherid;
                teacherPassword.Teacherpassword1 = "827ccb0eea8a706c4c34a16891f84e7b";
                teacherinfomation.Phone = (beginPhone++).ToString();
                teacherinfomation.Departmentid = Enum.GetName(typeof(DepartmentId), (i % 4)).ToString()+ "20160001";
                studentRepo.AddTeacher(teacherinfomation);
                studentRepo.AddTeacherPwd(teacherPassword);
            }
        }
    }
}
